package com.fjh.test;

import com.fjh.pojo.ShoppingCart;
import com.fjh.pojo.Product;
import com.fjh.service.ProductService;

public class Main {
    public static void main(String[] args) {
        // 创建商品服务和购物车对象
        ProductService productService = new ProductService();
        ShoppingCart shoppingCart = new ShoppingCart();

        // 添加几个商品到数据库
        productService.add(new Product("1", "Product 1", 10));
        productService.add(new Product("2", "Product 2", 15));
        productService.add(new Product("3", "Product 3", 20));

        // 从数据库中查找商品并添加到购物车
        Product product1 = productService.findById("1");
        Product product2 = productService.findById("2");
        Product product3 = productService.findById("3");

        shoppingCart.add(product1);
        shoppingCart.add(product2);
        shoppingCart.add(product3);

        // 打印购物车中的商品
        System.out.println("Shopping Cart Items:");
        for (Product product : shoppingCart.listAll()) {
            System.out.println("ID: " + product.getId() + ", Name: " + product.getName() + ", Stock: " + product.getStock());
        }

        // 从购物车中移除商品
        shoppingCart.remove("1");

        // 打印更新后的购物车中的商品
        System.out.println("Updated Shopping Cart Items:");
        for (Product product : shoppingCart.listAll()) {
            System.out.println("ID: " + product.getId() + ", Name: " + product.getName() + ", Stock: " + product.getStock());
        }
    }
}

